package com.mt.sdk.ble.model;

import com.mt.sdk.tools.MTTools;
import android.bluetooth.BluetoothGattCharacteristic;

public class WriteCharactAction extends BLEBaseAction {
	private BluetoothGattCharacteristic charact;
	private byte[] datas;

	public WriteCharactAction(BluetoothGattCharacteristic charact, byte[] datas, Option option) {
		super(ActionType.WRITECHACT, option);
		this.charact = charact;
		this.datas = datas;
	}

	// 提取分段后的数据
	private int point = 0;

	public byte[] getPerdatas() {
		if ((datas == null) || (point >= datas.length)) {
			return null;
		}
		byte getbyte[];
		if ((option.getPerlenght() + point) > datas.length) {
			getbyte = new byte[datas.length - point];
			MTTools.arraycopy(datas, point, getbyte, 0, getbyte.length);
		} else {
			getbyte = new byte[option.getPerlenght()];
			MTTools.arraycopy(datas, point, getbyte, 0, getbyte.length);
		}
		point += getbyte.length;
		return getbyte;
	}

	public BluetoothGattCharacteristic getCharact() {
		return charact;
	}

	public void setCharact(BluetoothGattCharacteristic charact) {
		this.charact = charact;
	}

	public void onSendDatas(byte[] datas) {

	}
}
